<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload=function(){
            //1.获取画布
            var canvas=document.getElementById('canvas');
            //2.获取画笔
            var cx=canvas.getContext('2d');
            //3.设置画笔样式
            cx.fillStyle='red';
            cx.strokeStyle='black';
            //4.开70始绘制
            cx.beginPath();
            cx.moveTo(5,140);
            cx.lineTo(205,140);
            cx.closePath();
            cx.stroke();

            cx.beginPath();
            cx.moveTo(205,140);
            cx.lineTo(35,20);
            cx.closePath();
            cx.stroke();

            cx.beginPath();
            cx.moveTo(35,20);
            cx.lineTo(105,210);
            cx.closePath();
            cx.stroke();

            cx.beginPath();
            cx.moveTo(105,210);
            cx.lineTo(175,20);
            cx.closePath();
            cx.stroke();

            cx.beginPath();
            cx.moveTo(175,20);
            cx.lineTo(5,140);
            cx.closePath();
            cx.stroke();
        }
    </script>
</head>
<body>
    <canvas id="canvas" width="500px" height="500px" style="background-color: #ccc;"></canvas>
</body>
</html>